import {Component, Input, Output, EventEmitter, OnChanges} from '@angular/core';
import {BtnsGen} from './interface';
import {BtnInfo} from '@list-page';

@Component({
    selector: 'kylin-list-page-buttons',
    templateUrl: './buttons.component.html',
    styleUrls: [
        './buttons.component.less'
    ]
})
export class ButtonsComponent implements OnChanges {
    @Input() btnsGen: BtnsGen;
    @Output() klClick = new EventEmitter<BtnInfo>();
    sortedBtnsGen: BtnsGen;

    @Input() indeterminate: boolean;
    @Input() allChecked: boolean;
    @Input() dataLen: number;
    @Input() funSet: any;
    @Input() selectData: any;

    ngOnChanges(changes) {
        if (changes.btnsGen) {
            this.btnsSort();
        }
    }

    btnsSort() {
        // TODO 待完成，若项目有特定排序要求，则完善此函数
        this.sortedBtnsGen = this.btnsGen;
    }

    processClass(className) {
        return {[className]: !!className};
    }

    handleBtnsClick(btnInfo: BtnInfo) {
        this.klClick.emit(btnInfo);
    }
}
